//
//  KYZXUserInfo.m
//  KuYouZiXun
//
//  Created by lanou on 15/9/5.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "KYZXUserInfo.h"

#import "KYZXScreen.h"

@implementation KYZXUserInfo

static KYZXUserInfo *userInfo = nil;

+ (KYZXUserInfo *)standardKYZXUserInfo
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        userInfo = [[KYZXUserInfo alloc] init];
    });
    return userInfo;
}

- (id)init{

    if (self = [super init]) {
    [self getUserDefaultsColor];
    [self getUserDefaultsImagePlay];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"changeColor" object:nil];
       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeImagePlay:) name:@"changeImagePlay" object:nil];
    }
    return self;
}

//获取用户配色方案信息
- (void)getUserDefaultsColor{
    
    NSString *userColorInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"配色方案"];
    if ([userColorInfo isEqualToString:@"日间模式"]|| userColorInfo == nil) {
        self.backgroundColor = DAY_BACKGROUND_COLOR;
        self.textColor = DAY_TEXT_COLOR;
    }
    else{
        self.backgroundColor = NIGHT_BACKGROUND_COLOR;
        self.textColor = NIGHT_TEXT_COLOR;
    }
}

- (void)changeColor:(NSNotification *)info{

    NSString *infoStr = info.userInfo[@"配色方案"];
    if ([infoStr isEqualToString:@"日间模式"]) {
        self.backgroundColor = DAY_BACKGROUND_COLOR;
        self.textColor = DAY_TEXT_COLOR;
    }
    else{
        self.backgroundColor = NIGHT_BACKGROUND_COLOR;
        self.textColor = NIGHT_TEXT_COLOR;
    }
    
}


- (void)getUserDefaultsImagePlay{

    NSString *userColorInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"图片方案"];
    if ([userColorInfo isEqualToString:@"有图模式"] || userColorInfo == nil) {
        self.isImagePlay = YES;
    }
    else{
        self.isImagePlay = NO;
    }
}

- (void)changeImagePlay:(NSNotification *)info{

    NSString *infoStr = info.userInfo[@"图片方案"];
    if ([infoStr isEqualToString:@"有图模式"]) {
        self.isImagePlay = YES;
    }
    else{
        self.isImagePlay = NO;
    }
    
}
#pragma mark - 添加 移除 观察者
- (void)addObserver:(NSObject *)observer{

    [self addObserver:observer forKeyPath:@"backgroundColor" options:NSKeyValueObservingOptionNew context:nil];
     [self addObserver:observer forKeyPath:@"textColor" options:NSKeyValueObservingOptionNew context:nil];
    [self addObserver:observer forKeyPath:@"isImagePlay" options:NSKeyValueObservingOptionNew context:nil];
}

- (void)removeObserver:(NSObject *)observer {

    [self removeObserver:observer forKeyPath:@"backgroundColor"];
    [self removeObserver:observer forKeyPath:@"textColor"];
    [self removeObserver:observer forKeyPath:@"isImagePlay"];
}

@end
